package tr.edu.yildiz.ce.dap.appagent.client;

import tr.edu.yildiz.ce.dap.appagent.command.deployment.base.CommandConstants;
import tr.edu.yildiz.ce.dap.appagent.exception.AgentCommunicationException;
import tr.edu.yildiz.ce.dap.appagent.exception.AgentMessageException;
import tr.edu.yildiz.ce.dap.appagent.model.Actions;
import tr.edu.yildiz.ce.dap.appagent.model.Component;
import tr.edu.yildiz.ce.dap.appagent.model.ComponentList;
import tr.edu.yildiz.ce.dap.appagent.model.DapMessage;
import tr.edu.yildiz.ce.dap.appagent.util.DeploymentConstants;

public class InstallCommand {

	public static void main(String[] args) throws AgentCommunicationException, AgentMessageException {
		DapMessage dapMessage = new DapMessage();
		dapMessage.setCommand(CommandConstants.INSTALL);
		dapMessage.setAppName("sampe_app");
		dapMessage.setAppVersion("2.3");
		dapMessage.setComponentList(new ComponentList());
		
		Component c1 = new Component();
		c1.setName("sample_app_dao");
		c1.setVersion("2.3.0");
		c1.setUrl("ftp://localhost/repo/sample_app_dao_2.3.0.jar");
		c1.setActions(new Actions());
		c1.getActions().getAction().add(DeploymentConstants.Action.INSTALL);
		
		dapMessage.getComponentList().getComponent().add(c1);
		
		Component c2 = new Component();
		c2.setName("sample_app_service");
		c2.setVersion("2.3.0");
		c2.setUrl("ftp://localhost/repo/sample_app_service_2.3.0.jar");
		c2.setActions(new Actions());
		c2.getActions().getAction().add(DeploymentConstants.Action.INSTALL);
		c2.getActions().getAction().add(DeploymentConstants.Action.START);
		
		dapMessage.getComponentList().getComponent().add(c2);
//		DapMessage output = CommandUtil.sendMessage(dapMessage, "127.0.0.1", AgentProperties.getInstance().getListeningPort().intValue());
//		System.out.println(output.getResponse());
	}
	
}
